package com.yuchen.ishop.service.goods;

import com.yuchen.core.MyPager;
import com.yuchen.ishop.entity.GoodsTemplate;
import com.yuchen.jaxrs.Responses;
import com.yuchen.jaxrs.restclient.RestClientUtils;
import com.yuchen.utils.config.ConfigUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Service
public class GoodsTemplateRestClient {

    public Responses insert(GoodsTemplate template) {
        String url = ConfigUtils.config.get("goodstemplate_insert");
        Responses responses = RestClientUtils.post(Responses.class, template, url);
        return responses;
    }

    public MyPager finds(Map params) {
        String url = ConfigUtils.config.get("goodstemplate_find");
        return RestClientUtils.post(MyPager.class, params, url);
    }

    public GoodsTemplate get(Long id) {
        String url = ConfigUtils.config.get("goodstemplate_get");
        Map map = new HashMap(1);
        map.put("id",id);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.get(GoodsTemplate.class, url);
    }

    public Responses update(GoodsTemplate goodsTemplate) {
        String url = ConfigUtils.config.get("goodstemplate_update");
        Responses responses = RestClientUtils.post(Responses.class, goodsTemplate, url);
        return responses;
    }

    public Responses delete(Long id) {
        String url = ConfigUtils.config.get("goodstemplate_delete");
        Map map = new HashMap(1);
        map.put("id",id);
        url = RestClientUtils.url(url,map);
        Responses responses = RestClientUtils.delete(Responses.class, url);
        return responses;
    }

    public boolean isExistTemplate(Long templateId, Long xiaoerId) {
        String url = ConfigUtils.config.get("goodstemplate_isExistTemplate");
        Map map = new HashMap(2);
        map.put("id",templateId);
        map.put("xiaoerId",xiaoerId);
        return RestClientUtils.post(Boolean.class,map,url);
    }
}
